package com.example.demo.day0226;

import java.util.Comparator;

public class Person implements Comparator<Person> {//建立一个person类实现comparator接口
        int age;
        String name;

        public Person() {
        }

        public Person( int age,String name) {
            this.age=age;
            this.name=name;
        }

        public int compare(Person o1, Person o2) {//重写compare方法
            if (o1.age>o2.age){
                return 1;
            }else  if (o1.age<o2.age){
                return -1;
            }else{
                return 0;
            }
        }
    }

